/*
 * @Description: 示例 'counter'为id需唯一，不能重复
 * @Author: Chenx
 * @Date: 2023-03-03 11:21:57
 * @LastEditors: Chenx
 * @LastEditTime: 2023-03-03 15:21:50
 */
import { defineStore } from 'pinia'

export const counterStore = defineStore('counter', {
  state: () => {
    return {
      count: 25
    }
  },
  getters: {
    getCount: (state) => {
      return (num: number) => state.count + num
    },
    getComputedCount (): number {
      return this.count + this.getCount(this.count) // 调用其它getter
    }
  },
  actions: {
    saveCount (count: number) {
      this.count = count
    }
  },
  persist: {
    enabled: true,
    strategies: [{ storage: localStorage, paths: ['token', 'userInfo'] }]
  }
})
